import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

import postCssPxToRem from "postcss-pxtorem"

export default defineConfig({
  plugins: [vue()

  ],
  // 设为false 可以避免 vite 清屏而错过在终端中打印某些关键信息
  clearScreen: false,
  resolve: {
    // preserveSymlinks: false, // 启用此选项会使 Vite 通过原始文件路径确定文件身份

    alias: {
      '@': path.resolve(__dirname, "src"),
    },
    extensions: [".ts", ".vue", ".js", ".jsx", ".tsx"], // 导入时想要省略的扩展名列表。
  },
  server: {
    proxy: {
      // 严选线上接口
      '/yx': {
        target: 'https://m.you.163.com',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/yx/, '')
      },
      // 前台PC项目的接口
      '/sph': {
        target: 'http://sph-h5-api.atguigu.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/sph/, '')
      }
    }
  },
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 37.5, // 1rem的大小
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
        })
      ]
    },
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        additionalData: `@import "${path.resolve(__dirname, 'src/styles/index.less')}";`,
      },
    },
  },

})
